﻿using System;
using System.Diagnostics;
using PluginSample2.BarModel;
using Plugins.Base;
using StockModel;
using Utils;

namespace PluginSample2
{
	[Serializable]
	internal class DecisionEngineData : PropertyChangedNotifier, ICopyable<DecisionEngineData>
	{
		#region Attributes

		private EngineState _state;
		private EngineState _previousState;
		private int _barCount;
		[NonSerialized] private Quotation _lastQuotation;
		private DateTime _processedDay;
		private Bar _currentBar;
		private Bar _previousBar;

		#endregion

		#region Properties

		public EngineState State
		{
			get
			{
				return _state;
			}
			set
			{
				if (_state != value)
				{
					_state = value;
					base.OnPropertyChanged("State");
				}
			}
		}

		public EngineState PreviousState
		{
			get
			{
				return _previousState;
			}
			set
			{
				if (_previousState != value)
				{
					_previousState = value;
					base.OnPropertyChanged("PreviousState");
				}
			}
		}

		public int BarCount
		{
			get
			{
				return _barCount;
			}
			set
			{
				if (_barCount != value)
				{
					Debug.WriteLine("BarCount: " + value);
					_barCount = value;
					base.OnPropertyChanged("BarCount");
				}
			}
		}

		public Quotation LastQuotation
		{
			get
			{
				return _lastQuotation;
			}
			set
			{
				if (_lastQuotation != value)
				{
					_lastQuotation = value;
					base.OnPropertyChanged("LastQuotation");
				}
			}
		}

		public DateTime ProcessedDay
		{
			get
			{
				return _processedDay;
			}
			set
			{
				if (_processedDay != value)
				{
					_processedDay = value;
					base.OnPropertyChanged("ProcessedDay");
				}
			}
		}

		public Bar CurrentBar
		{
			get
			{
				return _currentBar;
			}
			set
			{
				if (_currentBar != value)
				{
					//Debug.WriteLine("Current Bar: " + value.Start + " - Max: " + value.Maximum + " - Min: " + value.Minimum);
					_currentBar = value;
					base.OnPropertyChanged("CurrentBar");
				}
			}
		}

		public Bar PreviousBar
		{
			get
			{
				return _previousBar;
			}
			set
			{
				if (_previousBar != value)
				{
					_previousBar = value;
					base.OnPropertyChanged("PreviousBar");
				}
			}
		}

		#endregion

		#region Public Methods

		public DecisionEngineData()
		{
			this.State = DecisionEngineState.WaitingOpen;
		}

		public void Copy(DecisionEngineData source)
		{
			this.State = source.State;
			this.ProcessedDay = source.ProcessedDay;
			this.PreviousState = source.PreviousState;
			this.BarCount = source.BarCount;
			this.CurrentBar = source.CurrentBar;
			this.PreviousBar = source.PreviousBar;
		}

		#endregion
	}
}
